package com.mingmen.canting.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mingmen.canting.R;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by guohao on 2017/9/6.
 */

public class CaiGouiLeftAdapter extends RecyclerView.Adapter<CaiGouiLeftAdapter.ViewHolder> implements View.OnClickListener {

    private static final int MYLIVE_MODE_CHECK = 0;
    int mEditMode = MYLIVE_MODE_CHECK;

    private Context context;
    private List<String> mMyLiveList;
    private OnItemClickListener mOnItemClickListener;
    private int checkedPosition;

    public CaiGouiLeftAdapter(Context context, List<String> mMyLiveList) {
        this.context = context;
        this.mMyLiveList = mMyLiveList;
    }

    public void setDataList(List<String> mMyLiveList) {
        this.mMyLiveList = mMyLiveList;
        notifyDataSetChanged();
    }

    public void setCheckedPosition(int checkedPosition) {
        this.checkedPosition = checkedPosition;
        notifyDataSetChanged();
    }

    public List<String> getMyLiveList() {
        if (mMyLiveList == null) {
            mMyLiveList = new ArrayList<>();
        }
        return mMyLiveList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_caigouileft, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public int getItemCount() {
        return mMyLiveList.size();
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
//        final MyLiveList myLive = mMyLiveList.get(holder.getAdapterPosition());
        holder.mTvTitle.setText(mMyLiveList.get(position));

        if (position == checkedPosition) {
//            holder.mRootView.setBackgroundColor(Color.parseColor("#f3f3f3"));
            holder.mRootView.setBackground(context.getResources().getDrawable(R.mipmap.jinglicaiselect));
            holder.mTvTitle.setTextColor(context.getResources().getColor(R.color.white));
        } else {
//            holder.mRootView.setBackgroundColor(Color.parseColor("#FFFFFF"));
            holder.mRootView.setBackground(context.getResources().getDrawable(R.mipmap.jinglicai_noselect));
            holder.mTvTitle.setTextColor(context.getResources().getColor(R.color.red_normal));
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                mOnItemClickListener.onItemClickListener(holder.getAdapterPosition(), mMyLiveList);
                mOnItemClickListener.onItemClickListener(v, holder.getAdapterPosition(), mMyLiveList);
            }
        });


    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    @Override
    public void onClick(View v) {
        int position = (int) v.getTag();

    }

    public interface OnItemClickListener {
        //        void onItemClickListener(int pos, DaishenheListAdapter.ViewName viewName, List<MyLiveList> myLiveList);
        void onItemClickListener(View view, int pos,  List<String> myLiveLists);
    }

    public void setEditMode(int editMode) {
        mEditMode = editMode;
        notifyDataSetChanged();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {


        TextView mTvTitle;


        LinearLayout mRootView;


        public ViewHolder(View itemView) {
            super(itemView);

            mTvTitle = itemView.findViewById(R.id.tv_sort);


            mRootView = itemView.findViewById(R.id.linear_layout);

        }
    }


}
